package com.sxpi.course.feign.api;

import com.sxpi.course.dto.CourseDto;
import com.sxpi.common.result.R;
import com.sxpi.course.feign.callback.CourseServiceFeignFeignCallback;
import com.sxpi.course.vo.CoursePriseVo;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;

/**
 * @Author: 董伟豪
 * @Date: 2022/10/2 17:32
 * 定义Feign的接口
 * openFeign的兜底方案是监听服务的提供者的异常
 */
// @FeignClient(name = "sxpi-service-course",configuration = LogFeginConfiguration.class)
@FeignClient(name = "sxpi-service-course",fallbackFactory = CourseServiceFeignFeignCallback.class)
public interface CourseServiceFeign {

    /**
     * 查询课程信息并分页搜索
     * feign会对传递的参数来进行一个编码和解码的操作
     * @param courseDto
     * @return
     */
    @PostMapping("/course/page")
    R findCoursePage(@RequestBody CourseDto courseDto);

    /**
     * 查询全部的分类
     * @return
     */
    @PostMapping("/course/category")
    R findCategories();

    /**
     * 根据id查询出来的分类信息放入到缓存中
     * @param id
     * @return
     */
    @PostMapping("/course/get/{id}")
    R getCourseDetail(@PathVariable("id")Long id);

    /**
     * 查询相关课程信息
     * @return
     */
    @PostMapping("/course/relation")
    R findCoursePageRelation(@RequestBody CourseDto courseDto);

    /**
     * 根据课程id查询对应章节的信息
     * @param courseId 课程id
     * @return
     */
    @PostMapping("/course/chapterlesson/{courseId}")
    R getChapterLessonDetail(@PathVariable("courseId")Long courseId);

    /**
     * 根据课程id查询对应章节的信息（去除空字段）
     * @param courseId
     * @return
     */
    @PostMapping("/course/chapterlessonmap/{courseId}")
    R getChapterLessonDetailMap(@PathVariable("courseId")Long courseId);

    /**
     * 测试sentinel
     * @return
     */
    @PostMapping("/course/sentinel/test")
    R findSentinelByZeroTest();


    /**
     * 保存用户点赞信息
     * @param coursePriseVo
     * @return
     */
    @PostMapping("/course/parise/save")
    R insertCoursePrise(@RequestBody CoursePriseVo coursePriseVo);

    /**
     * 查看某个用户的课程点赞记录
     * @param courseId
     * @param userId
     * @return
     */
    @PostMapping("/course/parise/select/{courseId}/{userId}")
    R selectByCourseIdAndUserId(@PathVariable("courseId") Long courseId, @PathVariable("userId") Long userId);

    /**
     * 根据课程id查询总的点赞记录
     * @param courseId
     * @return
     */
    @PostMapping("/course/parise/count/{courseId}")
    R countByCourseId(@PathVariable("courseId") Long courseId);

    /**
     * 用户取消课程的点赞记录
     * @param courseId
     * @param userId
     * @return
     */
    @PostMapping("/course/parise/cancel/{courseId}/{userId}")
    R cancelCoursePrise(@PathVariable("courseId") Long courseId, @PathVariable("userId") Long userId);

    /**
     * 获取课程的点赞的总数排行
     * @return
     */
    @PostMapping("/course/parise/rank")
    R getCoursePriseRank();

    /**
     * 保存用户点赞信息 redisson锁
     * @param coursePriseVo
     * @return
     */
    @PostMapping("/course/parise/savelock")
    R insertCoursePriseLock(@RequestBody CoursePriseVo coursePriseVo);
}
